<template>
  <div>
    <el-card>
      <div slot="header" class="header">
        <div class="header-category">
          <span>销售额类别占比</span>
          <el-radio-group v-model="radio1">
            <el-radio-button label="全部渠道"></el-radio-button>
            <el-radio-button label="线上"></el-radio-button>
            <el-radio-button label="门店"></el-radio-button>
          </el-radio-group>
        </div>
      </div>
      <div class="charts-box"><div class="charts" id="charts"></div></div>
    </el-card>
  </div>
</template>

<script>
import * as echarts from 'echarts';
export default {
  components: {},
  data() {
    return {
      radio1: '全部渠道'
    };
  },
  mounted() {
    this.initCharts();
  },
  methods: {
    initCharts() {
      var chartDom = document.getElementById('charts');
      var myChart = echarts.init(chartDom);
      var option = {
        tooltip: {
          trigger: 'item'
        },
        title:{
          text: '视频',
          subtext: '2222232',
          left:'center',
          top:'center'
        },
        legend: {
          top: '5%',
          left: 'center'
        },
        series: [
          {
            name: 'Access From',
            type: 'pie',
            radius: ['40%', '70%'],
            avoidLabelOverlap: true,
            label: {
              show: true,
              position: 'outside'
            },
            emphasis: {
              label: {
                show: true,
                fontSize: '40',
                fontWeight: 'bold'
              }
            },
            labelLine: {
              show: true
            },
            data: [
              { value: 1048, name: 'Search Engine' },
              { value: 735, name: 'Direct' },
              { value: 580, name: 'Email' },
              { value: 484, name: 'Union Ads' },
              { value: 300, name: 'Video Ads' }
            ]
          }
        ]
      };
      option && myChart.setOption(option);
      myChart.on("mouseover", (params)=>{
        const {name, value} = params.data;
        myChart.setOption({
          title:{
            text: name,
            subtext: value,
            left:'center',
            top:'center'
          },
        })
      })
    }
  }
};
</script>
<style lang="less" scoped>
.header {
  padding-bottom: 5px;
  border-bottom: 1px solid #eeeeee;
}
.el-radio-group {
  margin-left: 20px;
}
.header-category {
  display: flex;
  justify-content: space-between;
  align-items: center;
}
.charts-box {
  height: 340px;
  .charts {
    width: 100%;
    padding: 10px;
    height: 340px;
  }
}
</style>
